package com.atguiigu.gmall;

import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.TimeZone;

/**
 * @author ：MJS
 * @date ：Created in 2021/5/8  18:15
 * @description：TODO
 */
public class Demo {
    public static void main(String[] args) throws JsonProcessingException {
        //@RequestBody  将  Json串转成pojo对象
        //@responseBody   将pojo对象转换成JSON串
        ObjectMapper objectMapper=new ObjectMapper();
        objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
        objectMapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
        objectMapper.setTimeZone(TimeZone.getTimeZone("GMT+8"));
        Map map=new HashMap<>();
        map.put("kkk","vv");
        map.put("123",null);
        map.put("curTime",new Date());
        //将对象转换成字符串
        String s = objectMapper.writeValueAsString(map);
        System.out.println(s);
        //将字符串转换成对象
        Map map1 = objectMapper.readValue(s, Map.class);


    }
}
